package com.system.connect.springboot_flowers.controller;

import com.system.connect.springboot_flowers.entity.FlowerDetail;
import com.system.connect.springboot_flowers.service.FlowerDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/flower-detail")
public class FlowerDetailController {
    @Autowired
    private FlowerDetailService flowerDetailService;

    @GetMapping("/{id}")
    public ResponseEntity<FlowerDetail> getById(@PathVariable Long id) {
        FlowerDetail flowerDetail = flowerDetailService.getById(id);
        return ResponseEntity.ok(flowerDetail);
    }

    @GetMapping
    public ResponseEntity<List<FlowerDetail>> getAll() {
        List<FlowerDetail> flowerDetails = flowerDetailService.getAll();
        return ResponseEntity.ok(flowerDetails);
    }

    @PostMapping
    public ResponseEntity<Void> save(@RequestBody FlowerDetail flowerDetail) {
        flowerDetailService.save(flowerDetail);
        return ResponseEntity.ok().build();
    }

    @PutMapping("/{id}")
    public ResponseEntity<Void> update(@PathVariable Long id, @RequestBody FlowerDetail flowerDetail) {
        flowerDetail.setId(id);
        flowerDetailService.update(flowerDetail);
        return ResponseEntity.ok().build();
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> delete(@PathVariable Long id) {
        flowerDetailService.delete(id);
        return ResponseEntity.ok().build();
    }
}
